//+------------------------------------------------------------------+
//|                                            VolumeCalcPending.mq4 |
//|                                                            kfeee |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "kfeee"

#property indicator_chart_window
//--- input parameters
extern color     Color=Black;
extern int       FontSize=10;
extern int       Corner=3;
extern int       precision=1;
extern bool      OnTick=true;

double diff=0.0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   ObjectCreate("Spread",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("Spread",OBJPROP_CORNER,Corner);
   ObjectSet("Spread",OBJPROP_XDISTANCE,20);
   ObjectSet("Spread",OBJPROP_YDISTANCE,20);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("Spread");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  string currencypair = Symbol();
  
  if(diff==0.0||diff!=MarketInfo(currencypair,MODE_ASK)-MarketInfo(currencypair,MODE_BID)){
   int digits = MarketInfo(currencypair,MODE_DIGITS);
   string spread = 0.0000;
   
   if(digits==5){
      spread = DoubleToStr((MarketInfo(currencypair,MODE_ASK)-MarketInfo(currencypair,MODE_BID))/0.0001,precision);
   }
   else{
      if(digits==3){
         spread = DoubleToStr((MarketInfo(currencypair,MODE_ASK)-MarketInfo(currencypair,MODE_BID))/0.01,precision);
      }
   }
   
   ObjectSetText("Spread","Spread: "+spread, FontSize,"Arial",Color);
   diff=MarketInfo(currencypair,MODE_ASK)-MarketInfo(currencypair,MODE_BID);
   }
  }
//+------------------------------------------------------------------+